#!/bin/bash
PACKAGE_NAME=arprec
MAJOR_VERSION=2
MINOR_VERSION=2
PATCH_LEVEL=$1
if [[ -z "$PATCH_LEVEL" ]]; then
  echo "Usage: makedist-win.sh patch-level"
  exit
fi

VERSION=$MAJOR_VERSION.$MINOR_VERSION.$PATCH_LEVEL
echo "Creating $PACKAGE_NAME-$VERSION distribution..."

DIR=/var/tmp/$PACKAGE_NAME-$VERSION
ORIG_DIR=`pwd`

rm -rf $DIR &&
mkdir -p $DIR &&
git ls-files -x '.gitignore' | xargs cp --parents --target-directory=$DIR &&
git log --no-merges >$DIR/ChangeLog &&
cd $DIR &&
mv config.h config.h.old &&
sed "s/devel/$PATCH_LEVEL/" config.h.old >config.h &&
rm -f config.h.old &&
cd .. &&
zip -r $PACKAGE_NAME-$VERSION.zip $PACKAGE_NAME-$VERSION &&
mv -f $PACKAGE_NAME-$VERSION.zip $ORIG_DIR &&
rm -rf $DIR
